package com.example.ten.image;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.example.ten.R;
import com.example.ten.Utils.ContentUtils;
import com.example.ten.base.BaseFragment;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;

/**
 * A simple {@link Fragment} subclass.
 */
public class ItemImageFragment extends BaseFragment {
    ImageView picIv;
    TextView titleTv,painterTv,summaryTv,authorTv;
    public ItemImageFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_item_image, container, false);
        initView(view);
        Bundle bundle = getArguments();
        ImageBean.ResultBean bean = (ImageBean.ResultBean) bundle.getSerializable("image");
//        加载数据
        loadData(getContext(),ContentUtils.PICTURE_DETATLS_URL+bean.getId(),ContentUtils.FILE_IMAGE_DETAIL,false,true,false);
        return view;
    }

    private void initView(View view) {
        picIv=view.findViewById(R.id.itemimage_iv);
        titleTv=view.findViewById(R.id.itemimage_tv_title);
        painterTv=view.findViewById(R.id.itemimage_tv_painter);
        summaryTv=view.findViewById(R.id.itemimage_tv_summary);
        authorTv=view.findViewById(R.id.itemimage_tv_author);
    }

    @Override
    public void showDataFromNet(String s) {
        Gson gson = new Gson();
        ImageDetailBean bean = gson.fromJson(s, ImageDetailBean.class);
        //        加载数据
        String imageURL = bean.getImage1();
        if (!TextUtils.isEmpty(imageURL)) {
            imageURL = ContentUtils.PICTURE_DISPLAY_URL+imageURL;
            Glide.with(getContext()).load(imageURL).into(picIv);
        }
        titleTv.setText(bean.getTitle());
        summaryTv.setText(bean.getText1());
        painterTv.setText(bean.getAuthorbrief());
        authorTv.setText(bean.getText2());
    }
}
